//
//  YLBindingInformationController.m
//  YLFinanceService
//
//  Created by she1323 on 2017/9/2.
//  Copyright © 2017年 she1323. All rights reserved.
//  绑定信息

#import "YLBindingInformationController.h"
#import "YLBindingInformationViewModel.h"
#import "YLTitleAllowCell.h"
#import "YLTitleArrowNoSubCell.h"
#import "YLGlobeHeader.h"
@interface YLBindingInformationController ()
@property (nonatomic, strong) YLBindingInformationViewModel *viewModel;
@end

@implementation YLBindingInformationController

- (YLBindingInformationViewModel *)viewModel
{
    if (!_viewModel) {
        _viewModel = [[YLBindingInformationViewModel alloc] init];
    }
    return _viewModel;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"绑定信息";
    
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([YLTitleAllowCell class]) bundle:nil] forCellReuseIdentifier:[YLTitleAllowCell cellID]];
}

- (instancetype)init
{
    return [self initWithStyle:UITableViewStyleGrouped];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.viewModel.groups.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    YLIconTitleModelGroup *group = self.viewModel.groups[section];
    return group.models.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    YLIconTitleModelGroup *group = self.viewModel.groups[indexPath.section];
    YLIconTitleContentModel *model = group.models[indexPath.row];
    
    YLTitleAllowCell *cell = [tableView dequeueReusableCellWithIdentifier:[YLTitleAllowCell cellID]];
        cell.contentModel =model;
        return cell;
  
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return YLScreenW * 30 / 750.0;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.001;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
     return YLScreenW * 93 / 750.0;;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    YLIconTitleModelGroup *group = self.viewModel.groups[indexPath.section];
    YLIconTitleModel *model = group.models[indexPath.row];
    if (model.clickBlock) {
        NSString *name = model.clickBlock();
        if (name) {
            [self.navigationController pushViewController:[[NSClassFromString(name) alloc] init] animated:YES];
        }
        
    }
    
    
}

@end
